﻿using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using dao;

namespace csharp_dao
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            String path = Directory.GetCurrentDirectory();
            String filePath = path + @"\\" + textBox1.Text;
            FileInfo fi = new FileInfo(filePath);
            if (fi.Exists)
            {
                textBox2.Text = @"파일이 존재합니다.";
                return;
            }

            dao.Database db = Class1.getDAODB(filePath);

            db.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            String path = Directory.GetCurrentDirectory();
            String filePath = path + @"\\" + textBox1.Text;

            dao.Database db = Class1.getDAODB(filePath, textBox3.Text);
            try
            {
                db.NewPassword(textBox3.Text, textBox4.Text);

                textBox2.Text = @"success";
            }
            catch (Exception ex)
            {
                textBox2.Text = ex.Message;
            }

            db.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            String path = Directory.GetCurrentDirectory();
            String filePath = path + @"\\" + textBox1.Text;

            dao.Database db = Class1.getDAODB(filePath, textBox3.Text);
            List<String> tbn = Class1.fnGetDAOTables1(db);
            textBox2.Text = String.Join("\r\n", tbn.ToArray());
        }

        private void button4_Click(object sender, EventArgs e)
        {
            String path = Directory.GetCurrentDirectory();
            String filePath = path + @"\\" + textBox1.Text;

            dao.Database db = Class1.getDAODB(filePath, textBox3.Text);
            List<String> fldn = Class1.fnGetDAOFields1(db);
            textBox2.Text = String.Join("\r\n", fldn.ToArray());
        }

        private void button5_Click(object sender, EventArgs e)
        {
            String path = Directory.GetCurrentDirectory();
            String filePath = path + @"\\" + textBox1.Text;

            dao.Database db = Class1.getDAODB(filePath, textBox3.Text);
            List<String> tbn = Class1.fnGetDAOTables2(db);
            textBox2.Text = String.Join("\r\n", tbn.ToArray());
        }

        private void button6_Click(object sender, EventArgs e)
        {
            String path = Directory.GetCurrentDirectory();
            String filePath = path + @"\\" + textBox1.Text;

            dao.Database db = Class1.getDAODB(filePath, textBox3.Text);
            List<String> fldn = Class1.fnGetDAOFields2(db);
            textBox2.Text = String.Join("\r\n", fldn.ToArray());
        }
    }
}
